package com.jprocms.module.cms.mq.consumer.bpm;

import com.jprocms.module.cms.mq.message.bpm.BpmDeployMessage;
import com.jprocms.module.cms.service.channel.ChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.function.Consumer;

/**
 * 针对 {@link BpmDeployMessage} 的消费者
 *
 * @author jprocms
 */
@Component
@Slf4j
public class BpmDeployConsumer {

    @Resource
    private ChannelService channelService;

    /**
     * 函数式编辑接收消息  bpmDeploy 和牌配置中    destination相同
     */
    @Bean
    public Consumer<BpmDeployMessage> bpmDeploy() {
        return message -> {
            log.info("接收到流程模型重新发布消息:旧ID {}, 新ID {}", message.getOldDefinitionId(), message.getDefinitionId());
            channelService.updateChannelWorkflowDefinitionId(message);
        };
    }
}